package com.example.permission.myjbm.adapter;


import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jbmsuppliers.R;
import com.example.permission.myjbm.activitys.IntegralDetail;
import com.example.permission.myjbm.config.Config;
import com.example.permission.myjbm.dao.BaseAdapter;
import com.jbm.jbmsupplier.util.VoucherEntity;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 礼券中心的适配器
 *
 */

public class CertificateAdapter extends BaseAdapter {

    private final SimpleDateFormat formate;
    private List<VoucherEntity> arr;

    public CertificateAdapter(List<VoucherEntity> arr, Context c) {
        super(c);
        formate=new SimpleDateFormat("yyyy-MM-dd");
        this.arr = arr;
    }

    @Override
    protected Object getHolder(View convertView) {
        return new MyHolder(convertView);
    }

    @Override
    protected int getLayout() {
        return R.layout.dsy_item_certificate_lv;
    }

    @Override
    protected Object getArr() {
        return arr;
    }

    @Override
    protected void initView(Object holder, final int position) {
        Picasso.with(c).load(Config.PHOTOPATH+arr.get(position).getPicpath()).into(  ((MyHolder)holder).certificateImg);
        ((MyHolder)holder).certificateTitle.setText(arr.get(position).getMemo());
        ((MyHolder)holder).certificateData.setText("有效期至: "+formate.format(arr.get(position).getExpireDate()));
        ((MyHolder)holder).certificateDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(c, IntegralDetail.class);
                intent.putExtra("isDetial",1);
                intent.putExtra("exp_id",arr.get(position).getVoucherId());
                c.startActivity(intent);

            }
        });
    }

    @Override
    protected void initListener(Object holder, int position) {

    }

    class MyHolder {
        ImageView certificateImg;
        TextView certificateTitle;
        TextView certificateData;
        TextView certificateDetails;

        public MyHolder(View convertView) {
            certificateImg= (ImageView)convertView.findViewById(R.id.certificate_img);
            certificateTitle= (TextView)convertView.findViewById(R.id.certificate_title);
            certificateData= (TextView)convertView.findViewById(R.id.certificate_data);
            certificateDetails= (TextView)convertView.findViewById(R.id.certificate_details);

        }

    }
}
